VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmBasicARSalesInvoice 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8295
   ClientLeft      =   840
   ClientTop       =   120
   ClientWidth     =   13200
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   8295
   ScaleWidth      =   13200
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ITGTab SSTab1 
      Height          =   5550
      Left            =   0
      TabIndex        =   37
      Top             =   30
      Width           =   13050
      _ExtentX        =   23019
      _ExtentY        =   9790
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   1
      Tab(0)ContCtrlCap(1)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   -2147483639
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   -2147483633
      DisabledTabForeColor=   -2147483627
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   4875
         Left            =   -75000
         TabIndex        =   36
         Top             =   315
         Width           =   13050
         _ExtentX        =   23019
         _ExtentY        =   8599
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   7
         BeginProperty Column00 
            DataField       =   "cInvNo"
            Caption         =   "Statement No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cCode"
            Caption         =   "Customer"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cSMan"
            Caption         =   "Salesman"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cMSCode"
            Caption         =   "Market Segment"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nGross"
            Caption         =   "Gross"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "cRemarks"
            Caption         =   "Remarks"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1379.906
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1275.024
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1365.165
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1305.071
            EndProperty
            BeginProperty Column06 
               Locked          =   -1  'True
               ColumnWidth     =   2459.906
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   5235
         Left            =   0
         Top             =   315
         Width           =   13050
         _ExtentX        =   23019
         _ExtentY        =   9234
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Billing Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.CommandButton cmdPickWork 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2760
            Picture         =   "frmBasicARSalesInvoice.frx":0000
            Style           =   1  'Graphical
            TabIndex        =   18
            Top             =   2385
            Width           =   300
         End
         Begin VB.CommandButton cmdPickProject 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2760
            Picture         =   "frmBasicARSalesInvoice.frx":014A
            Style           =   1  'Graphical
            TabIndex        =   16
            Top             =   2085
            Width           =   300
         End
         Begin VB.ComboBox cboTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8385
            Style           =   2  'Dropdown List
            TabIndex        =   9
            Top             =   1150
            Width           =   1710
         End
         Begin VB.CommandButton cmdPickCode 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2740
            Picture         =   "frmBasicARSalesInvoice.frx":0294
            Style           =   1  'Graphical
            TabIndex        =   5
            Top             =   870
            Width           =   300
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicARSalesInvoice.frx":03DE
            Left            =   8385
            List            =   "frmBasicARSalesInvoice.frx":03E8
            Style           =   2  'Dropdown List
            TabIndex        =   2
            Top             =   555
            Width           =   1710
         End
         Begin VB.ComboBox cboIntTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8400
            Style           =   2  'Dropdown List
            TabIndex        =   6
            Top             =   880
            Width           =   1710
         End
         Begin VB.ComboBox cboPaymentType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   8385
            Style           =   2  'Dropdown List
            TabIndex        =   12
            Top             =   1470
            Width           =   1710
         End
         Begin VB.ComboBox cboTaxType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicARSalesInvoice.frx":040E
            Left            =   8385
            List            =   "frmBasicARSalesInvoice.frx":042D
            Style           =   2  'Dropdown List
            TabIndex        =   14
            Top             =   1770
            Width           =   1710
         End
         Begin ITGControls.ComunionFrames ComunionFrames3 
            Height          =   2265
            Left            =   0
            Top             =   3090
            Width           =   13050
            _ExtentX        =   23019
            _ExtentY        =   3995
            FrameColor      =   4210752
            BackColor       =   16243138
            FillColor       =   16243138
            RoundedCorner   =   0   'False
            Caption         =   "Sales Summary"
            Alignment       =   0
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ThemeColor      =   5
            ColorFrom       =   16243138
            Begin ITGControls.ITGTextBox txtFreightAllow 
               Height          =   285
               Left            =   75
               TabIndex        =   29
               Top             =   780
               Visible         =   0   'False
               Width           =   2985
               _ExtentX        =   5054
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Freight Allowance"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1350
               TextBoxWidth    =   1575
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtFreightCharges 
               Height          =   285
               Left            =   75
               TabIndex        =   28
               Top             =   480
               Visible         =   0   'False
               Width           =   2985
               _ExtentX        =   5054
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Freight Charges"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1350
               TextBoxWidth    =   1575
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGCommandButton ITGCommandButton1 
               Height          =   480
               Left            =   4020
               TabIndex        =   22
               Top             =   1245
               Visible         =   0   'False
               Width           =   1395
               _ExtentX        =   2461
               _ExtentY        =   847
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Caption         =   "Balance Info >>"
            End
            Begin ITGControls.ITGCommandButton cmdInvoices 
               Height          =   480
               Left            =   4020
               TabIndex        =   21
               Top             =   780
               Visible         =   0   'False
               Width           =   1395
               _ExtentX        =   2461
               _ExtentY        =   847
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Caption         =   "SO Info >>"
            End
            Begin ITGControls.ITGTextBox txtBalance 
               Height          =   285
               Left            =   9825
               TabIndex        =   35
               TabStop         =   0   'False
               Top             =   1680
               Width           =   2955
               _ExtentX        =   5001
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Balance"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   940
               TextBoxWidth    =   1955
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtCredit 
               Height          =   285
               Left            =   9825
               TabIndex        =   34
               TabStop         =   0   'False
               Top             =   1380
               Width           =   2955
               _ExtentX        =   5001
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Credit"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   940
               TextBoxWidth    =   1955
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtDebit 
               Height          =   285
               Left            =   9825
               TabIndex        =   33
               TabStop         =   0   'False
               Top             =   1080
               Width           =   2955
               _ExtentX        =   5001
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Debit"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   940
               TextBoxWidth    =   1955
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtPayment 
               Height          =   285
               Left            =   9825
               TabIndex        =   32
               TabStop         =   0   'False
               Top             =   780
               Width           =   2955
               _ExtentX        =   5001
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Payment"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   940
               TextBoxWidth    =   1955
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtReturns 
               Height          =   285
               Left            =   9810
               TabIndex        =   31
               TabStop         =   0   'False
               Top             =   480
               Width           =   2970
               _ExtentX        =   5027
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Returns"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   940
               TextBoxWidth    =   1970
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtGross 
               Height          =   285
               Left            =   5970
               TabIndex        =   30
               TabStop         =   0   'False
               Top             =   480
               Width           =   3045
               _ExtentX        =   5159
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Net Sales"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1100
               TextBoxWidth    =   1885
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtVatAmount 
               Height          =   285
               Left            =   5970
               TabIndex        =   47
               TabStop         =   0   'False
               Top             =   780
               Width           =   3045
               _ExtentX        =   5159
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "VAT Amount"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1100
               TextBoxWidth    =   1885
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtGrossVat 
               Height          =   285
               Left            =   5970
               TabIndex        =   48
               TabStop         =   0   'False
               Top             =   1080
               Width           =   3045
               _ExtentX        =   5159
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Gross Amount"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1100
               TextBoxWidth    =   1885
               Enabled         =   0   'False
               LinkForeColor   =   0
            End
            Begin ITGControls.ITGTextBox txtDiscount 
               Height          =   285
               Left            =   5970
               TabIndex        =   57
               TabStop         =   0   'False
               Top             =   1380
               Width           =   3030
               _ExtentX        =   5133
               _ExtentY        =   503
               SendKeysTab     =   -1  'True
               BackColor       =   14737632
               LabelBackColor  =   16243138
               BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Text            =   "0"
               DataType        =   1
               DecimalPlace    =   2
               Label           =   "Discount"
               BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
                  Name            =   "Tahoma"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               LabelWidth      =   1100
               TextBoxWidth    =   1870
               LinkForeColor   =   0
            End
            Begin VB.Label lblStatus 
               Alignment       =   2  'Center
               BackColor       =   &H00F7D9C2&
               Caption         =   "Status"
               BeginProperty Font 
                  Name            =   "Tahoma"
                  Size            =   18
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               ForeColor       =   &H00C0C0C0&
               Height          =   405
               Left            =   165
               TabIndex        =   59
               Top             =   1470
               Width           =   3420
            End
            Begin VB.Label lblVat 
               Alignment       =   2  'Center
               BackColor       =   &H00F7D9C2&
               BeginProperty Font 
                  Name            =   "Tahoma"
                  Size            =   18
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   405
               Left            =   240
               TabIndex        =   58
               Top             =   540
               Visible         =   0   'False
               Width           =   3420
            End
         End
         Begin VB.CommandButton cmdPickSM 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2760
            Picture         =   "frmBasicARSalesInvoice.frx":0474
            Style           =   1  'Graphical
            TabIndex        =   24
            Top             =   1770
            Width           =   300
         End
         Begin VB.CommandButton cmdPickPD 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2740
            Picture         =   "frmBasicARSalesInvoice.frx":05BE
            Style           =   1  'Graphical
            TabIndex        =   11
            Top             =   1470
            Width           =   300
         End
         Begin VB.CommandButton cmdPickMS 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2740
            Picture         =   "frmBasicARSalesInvoice.frx":0708
            Style           =   1  'Graphical
            TabIndex        =   8
            Top             =   1170
            Width           =   300
         End
         Begin VB.ComboBox cboDocType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicARSalesInvoice.frx":0852
            Left            =   11160
            List            =   "frmBasicARSalesInvoice.frx":0854
            Style           =   2  'Dropdown List
            TabIndex        =   3
            Top             =   570
            Width           =   1485
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   4860
            TabIndex        =   1
            Tag             =   "Invoice Date"
            Top             =   570
            Width           =   1275
            _ExtentX        =   2249
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtInvNo 
            Height          =   285
            Left            =   165
            TabIndex        =   0
            Top             =   570
            Width           =   2565
            _ExtentX        =   4313
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Statement No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1155
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   165
            TabIndex        =   19
            Top             =   2700
            Width           =   6630
            _ExtentX        =   11483
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   5220
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGTextBox txtSMName 
            Height          =   285
            Left            =   3060
            TabIndex        =   27
            TabStop         =   0   'False
            Top             =   1770
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtSMCode 
            Height          =   285
            Left            =   165
            TabIndex        =   13
            Top             =   1770
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Salesman"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtMSDesc 
            Height          =   285
            Left            =   3060
            TabIndex        =   25
            TabStop         =   0   'False
            Top             =   1170
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtMSCode 
            Height          =   285
            Left            =   165
            TabIndex        =   7
            Top             =   1170
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Market Segment"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtPDDesc 
            Height          =   285
            Left            =   3060
            TabIndex        =   26
            TabStop         =   0   'False
            Top             =   1470
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPDCode 
            Height          =   285
            Left            =   165
            TabIndex        =   10
            Top             =   1470
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Product Division"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtDocType 
            Height          =   285
            Left            =   11430
            TabIndex        =   38
            Tag             =   "cboType"
            Top             =   540
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Invoice Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGCommandButton cmdLoad 
            Height          =   300
            Left            =   10605
            TabIndex        =   20
            Top             =   1770
            Visible         =   0   'False
            Width           =   1290
            _ExtentX        =   2275
            _ExtentY        =   529
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Caption         =   "Load Details"
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   8385
            TabIndex        =   49
            Tag             =   "cboType"
            Top             =   525
            Visible         =   0   'False
            Width           =   1485
            _ExtentX        =   2514
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Invoice Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1425
         End
         Begin ITGControls.ITGTextBox txtPaymentType 
            Height          =   285
            Left            =   8385
            TabIndex        =   50
            Tag             =   "cboPaymentType"
            Top             =   1500
            Visible         =   0   'False
            Width           =   1485
            _ExtentX        =   2514
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Payment Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1425
         End
         Begin ITGControls.ITGTextBox txtIntTerms 
            Height          =   285
            Left            =   8385
            TabIndex        =   51
            Tag             =   "cboIntTerms"
            Top             =   825
            Visible         =   0   'False
            Width           =   1485
            _ExtentX        =   2514
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1425
         End
         Begin ITGControls.ITGTextBox txtTaxType 
            Height          =   285
            Left            =   8385
            TabIndex        =   52
            Tag             =   "cboType"
            Top             =   1800
            Visible         =   0   'False
            Width           =   1485
            _ExtentX        =   2514
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Transaction Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1425
         End
         Begin ITGControls.ITGTextBox txtName 
            Height          =   285
            Left            =   3060
            TabIndex        =   54
            TabStop         =   0   'False
            Top             =   870
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtCode 
            Height          =   285
            Left            =   165
            TabIndex        =   4
            Top             =   870
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Customer"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtTerms 
            Height          =   285
            Left            =   8385
            TabIndex        =   56
            Tag             =   "cboIntTerms"
            Top             =   1230
            Visible         =   0   'False
            Width           =   1485
            _ExtentX        =   2514
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1425
         End
         Begin ITGControls.ITGTextBox txtProjectName 
            Height          =   285
            Left            =   3060
            TabIndex        =   60
            TabStop         =   0   'False
            Top             =   2085
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtProject 
            Height          =   285
            Left            =   165
            TabIndex        =   15
            Top             =   2085
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Project"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtWorkDesc 
            Height          =   285
            Left            =   3060
            TabIndex        =   61
            TabStop         =   0   'False
            Top             =   2385
            Width           =   3735
            _ExtentX        =   6482
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3675
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtWork 
            Height          =   285
            Left            =   165
            TabIndex        =   17
            Top             =   2385
            Width           =   2550
            _ExtentX        =   4286
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Work"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1140
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin VB.Label Label4 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Internal Terms"
            Height          =   285
            Index           =   1
            Left            =   6990
            TabIndex        =   55
            Top             =   840
            Width           =   1365
         End
         Begin VB.Label Label17 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Tax Type"
            Height          =   315
            Left            =   6990
            TabIndex        =   53
            Top             =   1770
            Width           =   1485
         End
         Begin VB.Label Label6 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Doc Type"
            Height          =   285
            Left            =   10290
            TabIndex        =   43
            Top             =   570
            Width           =   705
         End
         Begin VB.Label Label5 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Type"
            Height          =   285
            Left            =   6990
            TabIndex        =   42
            Top             =   570
            Width           =   600
         End
         Begin VB.Label Label1 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Date"
            Height          =   255
            Left            =   4185
            TabIndex        =   41
            Top             =   570
            Width           =   780
         End
         Begin VB.Label Label2 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Customer Terms"
            Height          =   270
            Index           =   1
            Left            =   6990
            TabIndex        =   40
            Top             =   1170
            Width           =   1365
         End
         Begin VB.Label Label3 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Payment Type"
            Height          =   285
            Left            =   6990
            TabIndex        =   39
            Top             =   1470
            Width           =   1305
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   44
      Top             =   8010
      Width           =   13200
      _ExtentX        =   23283
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   10056
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   2355
      Left            =   30
      Top             =   5565
      Width           =   13050
      _ExtentX        =   23019
      _ExtentY        =   4154
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Billing Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1035
         Left            =   4455
         MultiLine       =   -1  'True
         TabIndex        =   46
         Top             =   930
         Visible         =   0   'False
         Width           =   3930
      End
      Begin VB.ComboBox cboSI 
         Height          =   315
         Left            =   210
         Style           =   2  'Dropdown List
         TabIndex        =   45
         Top             =   1395
         Visible         =   0   'False
         Width           =   1395
      End
      Begin MSDataGridLib.DataGrid dtgSI 
         Height          =   1935
         Left            =   0
         TabIndex        =   23
         Top             =   420
         Width           =   13050
         _ExtentX        =   23019
         _ExtentY        =   3413
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   14
         BeginProperty Column00 
            DataField       =   "cRefNo"
            Caption         =   "Reference No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cWH"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nTPC"
            Caption         =   "TPC"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nSMCom"
            Caption         =   "Com %"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "cBatchID"
            Caption         =   "Batch ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "nFactor"
            Caption         =   "Factor"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   13321
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "cDiscount"
            Caption         =   "Discount "
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column12 
            DataField       =   "nNetPrice"
            Caption         =   "Net Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column13 
            DataField       =   "nAmount"
            Caption         =   "Total"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   13321
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               ColumnWidth     =   1184.882
            EndProperty
            BeginProperty Column01 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   0
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column03 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   3495.118
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   629.858
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               ColumnWidth     =   1019.906
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1695.118
            EndProperty
            BeginProperty Column07 
               Alignment       =   1
               Object.Visible         =   0   'False
               ColumnWidth     =   854.929
            EndProperty
            BeginProperty Column08 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   645.165
            EndProperty
            BeginProperty Column09 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1200.189
            EndProperty
            BeginProperty Column10 
               ColumnWidth     =   14.74
            EndProperty
            BeginProperty Column11 
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column12 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column13 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1695.118
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmBasicARSalesInvoice"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Object variables
Private oPrint As New clsPrinting

Private AutoNum As New clsAutoNumber '---Added
Public MenuName As String '---Added

'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

Private rsAuto As ADODB.Recordset
Dim sInvType As String

'Form mode enumeration
Enum eBasicSIMode
    Normal
    AddNewEdit
    Find
End Enum

Public Mode As eBasicSIMode

'Other declarations
Private net As Double
Private lNetOK, lNew As Boolean
Private lLessAmount As Boolean
Private lLessPercent As Boolean

Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable
Public strNo As String, X As String, sType As String
Public lSystemGeneratedSI As Boolean, lChangedTranNo As Boolean

'ADO Connection variables
Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

Private nLimit, nAR, nARPastDue, nPDC, nHold, nBounced, nSOAmtLeft, nLimitBalance As Double 'For credit limit purposes
Private lOverride As Boolean

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Private lSysTransDate As Boolean 'add by denz:2/17/2011 for transdate


Private Sub cboDocType_Click()
    txtDocType = Trim(cboDocType)
End Sub

Private Sub cboDocType_Change()
    txtDocType = Trim(cboDocType)
End Sub

Private Sub cboDocType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboIntTerms_Click()
    txtIntTerms = Trim(cboIntTerms)
End Sub

Private Sub cboIntTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPaymentType_Click()
    txtPaymentType = Trim(cboPaymentType)
End Sub

Private Sub cboPaymentType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPaymentType_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then TBNewLine
End Sub

Private Sub cboSI_Click()
    If dtgSI.Col = 1 Then
        rsDetail!cWH = cboSI
    End If
End Sub

Private Sub cboSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgSI.Col = 1 Then
            rsDetail!cWH = cboSI
            cboSI.Visible = False
            dtgSI.Col = 5
            dtgSI.Columns(5).Value = rsDetail!nQty
            dtgSI.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboSI.Visible = False
    End If
End Sub

Private Sub cboSI_LostFocus()
    cboSI.Visible = False
End Sub

Private Sub cboTerms_Click()
    txtTerms = Trim(cboTerms)
End Sub

Private Sub cboTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_Click()
    txtType = Trim(cboType)
End Sub
    
Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_LostFocus()
On Error Resume Next
    If UCase(txtType) = "AUTO-INVOICE" Then
        MsgBox "Invoice type Auto-Invoice are auto-generated.", vbInformation, msgTtl
        cboType.SetFocus
    End If
End Sub

Private Sub cboTaxType_Click()
    txtTaxType = Trim(cboTaxType)
End Sub

Private Sub cboTaxType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub
    
Private Sub cboTaxType_KeyDown(KeyCode As Integer, Shift As Integer)
    txtTaxType = Trim(cboTaxType)
End Sub

Private Sub cmdProject_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtSMCode)
    frmITGPicker.zType = QSalesman
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtSMCode = frmITGPicker.zCode
    txtSMName = frmITGPicker.zName
    If Trim(txtSMName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickProject_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtProject)
    frmITGPicker.zType = QProject
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtProject = frmITGPicker.zCode
    txtProjectName = frmITGPicker.zName
    If Trim(txtProjectName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickWork_Click()
    If lPickListActive Then Exit Sub
'    sFilterString = Trim(txtWork)
    frmITGPicker.zType = QWork
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'" ' and cProjectNo = '" & Trim(txtProject) & "'"
    
    frmITGPicker.Show vbModal
    txtWork = frmITGPicker.zCode
    txtWorkDesc = frmITGPicker.zName
    If Trim(txtWorkDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub dtgList_Click()
    If dtgList.Row = -1 Then Exit Sub
    ShowInvoiceBalance
End Sub

Private Sub txtProject_Change()
    txtProjectName = ""
    txtProjectName = GetValueFrTable("cProjectName", "Project_Maintenance", "cProjectNo = '" & Trim(txtProject) & "'")
End Sub

Private Sub txtProject_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtProject) = "" And Trim(txtProject) <> "" Then cmdPickProject_Click
End Sub

Private Sub txtTaxType_Change()
    'If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtTaxType) <> "" Or txtTaxType <> vbNullString Then
        cboTaxType = Trim$(txtTaxType)
    Else: cboTaxType.ListIndex = -1
    End If
    
    ComputeNet
    ComputeAmount
    ComputeGross
    ComputeTotal

End Sub

'Load picklist
Private Sub cmdLoad_Click()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbInformation, msgTtl
        cboType.SetFocus
        Exit Sub
    End If
    
    If Trim(txtCode) = "" Then
        MsgBox "Please input Customer ID.", vbInformation, msgTtl
        txtCode.SetFocus
        Exit Sub
    End If
    
    RepName = Trim(txtCode)
    
    'Reference Type
    Select Case Trim(cboType)
        Case "Invoice" 'Direct to SO
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType = ''Regular'''"
            frmRefList.mType = Sales_Invoice
        Case "Invoice w/ DR" 'With reference DR
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType in (''Invoice w/ DR'')'"
            frmRefList.mType = Sales_Delivery_Receipt
        Case "Billing Statement" 'Item file as picklist
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType in (''Billing Statement'')'"
            frmRefList.mType = Sales_Billing_Receipt
        Case "Reimbursement" 'Item file as picklist
            sCondition = "'" & COID & "', '" & txtCode & "', ' and a.cType in (''Issues'',''Sales'')'"
            frmRefList.mType = Reimbursement
    End Select
    
    If frmRefList.Visible = False Then frmRefList.Show vbModal
End Sub

Private Sub cmdPickCode_Click()
Dim rsUser As New ADODB.Recordset
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtCode)
    With frmITGPicker
        .zType = QCustomer
        'added condition
        frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
        .Show vbModal
        txtCode = .zCode
    End With
End Sub

Private Sub cmdPickMS_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtMSCode)
    frmITGPicker.zType = QMarketSegment
    frmITGPicker.Condition = "AND cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtMSCode = frmITGPicker.zCode
    txtMSDesc = frmITGPicker.zName
    If Trim(txtMSDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickPD_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QProductDivision
    frmITGPicker.Condition = "AND cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtPDCode = frmITGPicker.zCode
    txtPDDesc = frmITGPicker.zName
    If Trim(txtPDDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickSM_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtSMCode)
    frmITGPicker.zType = QSalesman
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtSMCode = frmITGPicker.zCode
    txtSMName = frmITGPicker.zName
    If Trim(txtSMName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgSI_AfterColUpdate(ByVal ColIndex As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 5, 6, 7, 8
            ComputeNet
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 11, 12
            ComputeNet
            ComputeAmount
    '       ComputeGross
    '       ComputeTotalDisc
            ComputeTotal
        Case 13
            ComputeNet
            ComputeAmount
            ComputeGross
            ComputeTotal
        Case 14
            ComputeNet
            ComputeAmount
            ComputeGross
            ComputeTotal
    End Select
End Sub

Private Sub dtgSI_ButtonClick(ByVal ColIndex As Integer)
    If ColIndex = 3 Then
        Call MoveText(txtLongDesc, dtgSI, dtgSI.Columns(3))
        txtLongDesc = rsDetail!cLongDesc & ""
    End If
    If Mode = AddNewEdit Then 'Exit Sub
        Select Case ColIndex
            Case 1
                Call LoadComboValues(cboSI, "cWH", "WHSE", "WHERE cCompanyID = '" & COID & "'")
                Call MoveCombo(cboSI, dtgSI, dtgSI.Columns(1))
                ComboLoadValue cboSI, Trim(dtgSI.Columns(1).Text)
            Case 2
                If rsHeader!cType = "Consignment" Then
                    If lPickListActive Then Exit Sub
                    sFilterString = Trim(dtgSI.Columns(2).Text)
                    frmITGPicker.zType = QProduct
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
                    frmITGPicker.Show vbModal
                    rsDetail!cItemNo = frmITGPicker.zCode
                    rsDetail!cDesc = frmITGPicker.zName
                    If Trim(Trim(dtgSI.Columns(2).Text)) <> "" Then SendKeys "{Tab}"
                End If
        End Select
    End If
End Sub

'Set the datagrid as active control
Private Sub dtgSI_Click()
    If Mode = AddNewEdit Then dtgName = dtgSI.Name
End Sub

Private Sub dtgSI_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgSI_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    If KeyAscii = 13 Then
        Select Case dtgSI.Col
            Case 5
                dtgSI_AfterColUpdate (5)
            Case 6
                dtgSI_AfterColUpdate (6)
            Case 7
                dtgSI_AfterColUpdate (7)
                SendKeys "{Tab}"
            Case 11
                dtgSI_AfterColUpdate (11)
                SendKeys "(Tab)"
            Case 12
                dtgSI_AfterColUpdate (12)
                SendKeys "{Tab}"
            Case 13
                dtgSI_AfterColUpdate (13)
                SendKeys "{Tab}"
            Case 14
                dtgSI_AfterColUpdate (14)
                SendKeys "{Tab}"
            Case Else
                SendKeys "{Tab}"
        End Select
    Else: KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If
End Sub

'Right click menu popup
Private Sub dtgSI_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgSI.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
    
    Set FrmName = Me
    FormSetup
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'BAR02'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    
    'BIR
    'Load combobox values
    sSQL = "(SELECT module_id FROM erp_sec_modules WHERE link = '" & Me.Name & "')"
    Call LoadComboValues(cboType, "RefType", "ComboValueSetUp", "Where RefModule = " & sSQL & " AND Visible = 1 and cCompanyID = '" & Trim(COID) & "'")
    
    'Call LoadComboValues(cboDocType, "cParamName", "PARAMETER_USER", "WHERE cType = 'BIR_INVDOCTYPE' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    
    'Load combobox values
    Call LoadComboValues(cboDocType, "cValue", "PARAMETER_USER", "WHERE cType = 'BSIDOCTYPE' AND cCompanyID = '" & Trim(COID) & "'")
    Call LoadComboValues(cboTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboIntTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboPaymentType, "cValue", "PARAMETER_SYSTEM", "WHERE cType = 'SOPAYTYPE'")
    Call LoadComboValues(cboTaxType, "cValue", "PARAMETER_USER", "WHERE cType = 'TAXTYPE' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")

    
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    lSystemGeneratedSI = True

    Mode = Find
    txtInvNo.Locked = False
    
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    Set FrmName = Me
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing
    
    Set frmBasicARSalesInvoice = Nothing
    lCloseWindow = True
End Sub

'Add new record to the recordset
Public Sub TBNew()


    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtInvNo.BackColor = &HE0FFFF
    Mode = AddNewEdit

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connDetail
        OpenNewConnection connHeader
        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else: vBM = rsHeader.Bookmark
    End If

    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Now
    rsHeader!cType = "Invoice w/ DR"       'GetValueFrTable("cValue", "system_option", "cCode = 'BIR_DEF_INVTYPE'")
    rsHeader!cPayType = "Credit"
    rsHeader!cPCCode = sDivision
    rsHeader!cdoctype = GetValueFrTable("cValue", "system_option", "cCode = 'BIR_DEF_INVDOCTYPE'")
    lblVat.Caption = ""

    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    SSTab1.ActiveTab = 0
    txtInvNo.SetFocus
    txtInvNo.Locked = True
    txtType.Text = "Billing Statement"
    txtDocType = "DOC 1"
    
          If lSystemGeneratedSI Then
                If rsHeader!cType = "Invoice w/ DR" Then
                    sInvType = "AUTO_NUMBER_SIDR"
                ElseIf rsHeader!cType = "Billing Statement" Then
                    sInvType = "AUTO_NUMBER_SIBILLING"
                ElseIf rsHeader!cType = "Reimbursement" Then
                    sInvType = "AUTO_NUMBER_SIBILLING"
                End If
                rsHeader!cInvNo = AutoNum.Generate_CtrlNo2(sInvType, Format(Now, "mm/dd/yyyy"))
                strNo = rsHeader!cInvNo
          End If


End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
    Else
        RSZero
        Mode = Find
    End If
    
    EditDetail False
    sbRS.Panels(2) = ""
    SetDataSource
    SetDataField

ErrorHandler:
    cboSI.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
Dim lNew As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then
        lBoolean = True
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_SI'") Then
            If Not lOverride Then
                If (UCase(Trim(cboType)) = "INVOICE") Then
                    If CDbl(txtGross) > (nLimitBalance) Then
                        MsgBox "Invoice Gross exceeds the allowable credit limit balance." & vbCr & _
                                "Transaction cannot be saved.", vbInformation, msgTtl
                        Exit Sub
                    End If
                End If
            End If
        End If
    End If
    
    If Not MandatoryOK Then Exit Sub
    
    'System generated si no
    If rsHeader.Status = adRecNew Then
        lNew = True
    End If
    '----------------------
    'System generated number
    '------Added the code
    If rsHeader.Status = adRecNew Then
        If lSystemGeneratedSI Then
                If rsHeader!cType = "Invoice w/ DR" Then
                    MenuName = "AUTO_NUMBER_SIDR"
                ElseIf rsHeader!cType = "Billing Statement" Then
                    MenuName = "AUTO_NUMBER_SIBILLING"
                ElseIf rsHeader!cType = "Reimbursement" Then
                   MenuName = "AUTO_NUMBER_REIM"
                End If
                
            If AutoNum.Check_CtrlNo2(rsHeader, "SALES", "cInvNo", rsHeader!cInvNo, MenuName, rsHeader!dDate) <> rsHeader!cInvNo Then
                GetChild
                
                rsHeader!cInvNo = strNo
                
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
                Do Until rsDetail.EOF
                    rsDetail!cInvNo = strNo
                    rsDetail.MoveNext
                Loop
                
                GetChild
            End If
        End If
    End If
    
    
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    UpdateDRSI
    cn.CommitTrans
    connHeader.CommitTrans
    connDetail.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, False, , , , lACCancel, , , True, True, lACPrint, True, True
    Mode = Normal
        
    MsgBox "Record/s successfully saved.", vbInformation, msgTtl
    sbRS.Panels(2) = ""
    
    If lBoolean = False Then ' Edit
        cn.Execute ("UPDATE SALES SET dUpdated = GETDATE () WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")
    Else ' Insert
        cn.Execute ("UPDATE SALES SET dUpdated = GETDATE () WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")
    End If
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), IIf(lBoolean, "Inserted", "Updated")
    
    'Update GL Activity
    UpdateGLA "Update", "SI", Trim(txtInvNo)
    
    If lNew = True Then
        If lSystemGeneratedSI And strNo = rsHeader!cInvNo Then
            If rsHeader!cType = "Invoice w/ DR" Then
                UpdateControlNo strNo, rsHeader!cInvNo, "AUTO_NUMBER_SIDR"
                AutoNum.Update_CtrlNo2 strNo, MenuName, Format(Now, "mm/dd/yyyy")
            ElseIf rsHeader!cType = "Billing Statement" Then
                UpdateControlNo strNo, rsHeader!cInvNo, "AUTO_NUMBER_SIBILLING"
                AutoNum.Update_CtrlNo2 strNo, MenuName, Format(Now, "mm/dd/yyyy")
            ElseIf rsHeader!cType = "Reimbursement" Then
                UpdateControlNo strNo, rsHeader!cInvNo, "AUTO_NUMBER_REIM"
                AutoNum.Update_CtrlNo2 strNo, MenuName, Format(Now, "mm/dd/yyyy")
            End If
            GetChild
            rsHeader!cInvNo = strNo
            
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
            Do Until rsDetail.EOF
                rsDetail!cInvNo = strNo
                rsDetail.MoveNext
            Loop
            GetChild
        End If
    End If
        
    EditDetail False
    
ErrHandler:
    cboSI.Visible = False

    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, msgTtl
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            ShowInvoiceBalance
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else: RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, msgTtl
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If

End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    txtInvNo.Locked = True
    EditDetail True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark
    
        If rsHeader!cType = "Invoice w/ DR" Then
            lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = 'AUTO_NUMBER_SIDR'") 'add by denz:2/17/2011
            If lSysTransDate Then
                dtbDate.Enabled = True
            Else: dtbDate.Enabled = False
            End If
        ElseIf rsHeader!cType = "Billing Statement" Then
           lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = 'AUTO_NUMBER_SIBILLING'") 'add by denz:2/17/2011
            If lSysTransDate Then
                dtbDate.Enabled = True
            Else: dtbDate.Enabled = False
            End If
        ElseIf rsHeader!cType = "Reimbursement" Then
            lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = 'AUTO_NUMBER_REIM'") 'add by denz:2/17/2011
            If lSysTransDate Then
                dtbDate.Enabled = True
            Else: dtbDate.Enabled = False
            End If
        End If
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtInvNo)
    If rsHeader.RecordCount = 0 Then Exit Sub
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    If Not AllowDelete("delete") Then Exit Sub
    
    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    MsgBox "Invoice " & Trim(sID) & " has been deleted.", vbInformation, msgTtl
        
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE SALES_T WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE SALES WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtInvNo.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
On Error GoTo ErrorHandler
Dim sTemp As String
    If Mode = Find Then
        FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
        OpenNewConnection connHeader
        OpenNewConnection connDetail
    
        Set rsHeader = Nothing
        Set rsDetail = Nothing
        Set rsHeader = New ADODB.Recordset
        Set rsDetail = New ADODB.Recordset
    
        sTemp = Trim$(GetSearchString)
        If sTemp = "ERROR" Then
            MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
            txtInvNo.Locked = False
            txtInvNo.SetFocus
            Exit Sub
        End If
        
        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, IIf(sTemp = "", "", " WHERE cInvNo IN (SELECT cInvNo FROM SALES WHERE " & sTemp & ")")
        
        Set FrmName = Me
        FormLocking True
    
          If rsHeader.RecordCount = 0 Then
            FormWaitHide
            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
            RSZero
            FormSearch True
            SearchObj True
            Mode = Find
            Exit Sub
        End If
        SetDataSource
        SetDataField
        ShowInvoiceBalance
        txtInvNo.BackColor = &HE0FFFF
        Mode = Normal
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, False, , , , lACCancel, , , True, True, lACPrint, True, True
        'lblVat.Visible = False
        FormWaitHide
    Else
        lblVat.Visible = False
        lblStatus.Visible = False
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
    End If

ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If

End Sub

Public Sub TBAccountAffected()
    If rsHeader!lCancelled = 0 Then
        RepName = "SALES"
        frmAccountAffected.mModuleType = KSALES
        frmAccountAffected.mRefPK = txtInvNo.Text
        frmAccountAffected.Show vbModal
    End If
End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgSI.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
    ShowInvoiceBalance
End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
    ShowInvoiceBalance
End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
    ShowInvoiceBalance
End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    ShowInvoiceBalance
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbExclamation, msgTtl
        Exit Sub
    Else
        If (Trim(cboType) = "Consignment") Then
            If rsHeader!cInvNo = "" Then Exit Sub

            If Trim(txtName) = "" Then
                MsgBox "Please pick client.", vbExclamation, msgTtl
                Exit Sub
            End If

            If dtgName = "dtgSI" Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cInvNo = Trim(rsHeader!cInvNo)
                dtgSI.Col = 1
                dtgSI.Columns(1).Value = ""
                GetChild
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
                dtgSI.SetFocus
            End If
            
            dtgSI.Columns(4).Locked = True
            dtgSI.Columns(5).Locked = True
            dtgSI.Columns(6).Locked = True
            dtgSI.Columns(7).Locked = False
            dtgSI.Columns(4).Visible = False
            dtgSI.Columns(5).Visible = False
            dtgSI.Columns(6).Visible = False
            dtgSI.Columns(1).Text = GetValueFrTable("cWH", "WHSE", "cCode = '" & rsHeader!cCode & "'")
            rsDetail!nSDiscount = 0
            rsDetail!nSAdjustment = 0
            rsDetail!nMargin = 0
            dtgSI.Col = 2
        Else
            cmdLoad_Click 'Load details from list
            dtgSI.Columns(6).Locked = False
            dtgSI.Columns(4).Visible = True
            dtgSI.Columns(5).Visible = True
            dtgSI.Columns(6).Visible = True
        End If
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgSI.Name Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        rsHeader!nVatAmount = 0
        vBookMark = dtgSI.Bookmark
        GetChild
        dtgSI.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
        ComputeTotal
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub
    If Not (AllowDelete("cancel")) Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Cancelled"
    
    cn.Execute ("UPDATE SALES SET dUpdated = GETDATE () WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")

    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    cn.Execute ("UPDATE SALES SET lCancelled = 1 WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll
    
    sbRS.Panels(5) = "CANCELLED"
    lblStatus.Caption = "Cancelled"
    lblStatus.ForeColor = &H8080FF
    Mode = Normal
    
    MsgBox "Sale Invoice : " & Trim(txtInvNo) & " has been CANCELLED.", vbInformation, msgTtl

ErrorHandler:
    If err.Number = -2147217885 Or err.Number = -2147217864 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    If Trim(txtInvNo) = "" Then Exit Sub
    If rsHeader!cdoctype <> "" Then
        RepName = GetValueFrTable("cParamName", "PARAMETER_USER", "cType = 'BIR_INVDOCTYPE' AND cValue = '" & Trim(cboDocType) & "'")
    Else: RepName = "Basic_Sales_Invoice"
    End If
    cModule = "Basic_Sales_Invoice"
    InvNum = txtInvNo.Text
    oPrint.PrintReceipt Trim(txtInvNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgSI.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtInvNo.DataField = !cInvNo
        dtbDate.DataField = !dDate
        txtType.DataField = !cType
        txtDocType.DataField = !cdoctype
        txtCode.DataField = !cCode
        txtMSCode.DataField = !cMSCode
        txtPDCode.DataField = !cPDCode
        txtSMCode.DataField = !cSMan
        txtProject.DataField = !cProjectID
        txtWork.DataField = !cWorkID
        txtRemarks.DataField = !cRemarks
        txtIntTerms.DataField = !cIntTerm
        txtTerms.DataField = !cTerm
        txtPaymentType.DataField = !cPayType
        txtFreightCharges.DataField = !nFreightCharges
        txtFreightAllow.DataField = !nFreightAllow
        txtTaxType.DataField = !cTaxType
        txtVatAmount.DataField = !nVAT
        txtDiscount.DataField = !nDiscount
        txtBalance.DataField = !nBalance
        txtGross.DataField = !nSubTotal
        txtGrossVat.DataField = !nGross
        txtBalance.DataField = !nBalance
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtInvNo.Locked = True
        Else: txtInvNo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else: sbRS.Panels(2) = ""
        End If
        
        GetChild
        SetDataField
        ShowInvoiceBalance
        lblVat.Visible = False
        
        lblVat.Caption = IIf(rsHeader!lVatinclusive, "Inclusive", "Exclusive")
        If rsHeader!cTaxType = "VAT" Then
            lblVat.Visible = True
        Else: lblVat.Visible = False
        End If
        
        If rsHeader!lCancelled = True Then
            sbRS.Panels(5) = "CANCELLED"
            lblStatus.Visible = True
            lblStatus.Caption = "Cancelled"
            lblStatus.ForeColor = &H8080FF
        Else
            sbRS.Panels(4) = ""
            sbRS.Panels(5) = ""
            lblStatus.Caption = ""
            lblStatus.ForeColor = &HC0C0C0
        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtInvNo.Locked = False
    End If

    If Mode = AddNewEdit Then dtgSI.Refresh
    
ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub txtGross_Change()
    If Trim(txtGross.Text) <> "0.00" Then
        lblVat.Visible = True
    Else: lblVat.Visible = False
    End If
End Sub

Private Sub txtCode_Change()
    If Mode <> AddNewEdit Then
        txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        Exit Sub
    Else
        txtName = ""
        txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
    End If
    
    If Trim(txtName) <> "" Then
        If rsHeader.Status = adRecNew Then
            If (UCase(Trim(cboType)) = "INVOICE") Then
                If Not SICreditLimitOK Then
                    txtName = ""
                    txtMSCode = ""
                    txtPDCode = ""
                    txtSMCode = ""
                    cboTerms.ListIndex = -1
                    cboIntTerms.ListIndex = -1
                    Exit Sub
                End If
            End If
        End If
                
        rsHeader!cMSCode = GetValueFrTable("cMSCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cPDCode = GetValueFrTable("cPDCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cSMan = GetValueFrTable("cSMan", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cTerm = GetValueFrTable("cTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cIntTerm = GetValueFrTable("cIntTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cTaxType = GetValueFrTable("cTaxType", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        
        If Not lOverride Then txtRemarks.SetFocus
    Else
        txtMSCode = ""
        txtPDCode = ""
        txtSMCode = ""
        cboTerms.ListIndex = -1
        cboIntTerms.ListIndex = -1
    End If
End Sub

Private Sub txtCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) = "" And Trim(txtCode) <> "" Then cmdPickCode_Click
End Sub

Private Sub txtDocType_Change()
    If Trim(txtDocType) <> "" Or txtDocType <> vbNullString Then
        If GetValueFrTable("cValue", "PARAMETER_USER", "cType = 'BSIDOCTYPE' AND cValue = '" & Trim(txtDocType) & "' ", False) <> "" Then
            cboDocType = Trim(txtDocType)
        Else: cboDocType.ListIndex = -1
        End If
    Else: cboDocType.ListIndex = -1
    End If
End Sub

Private Sub txtFreightAllow_Change()
    ComputeTotal
End Sub

Private Sub txtFreightCharges_Change()
    ComputeTotal
End Sub

Private Sub txtIntTerms_Change()
On Error GoTo iTGErrorHandler
    If Trim(txtIntTerms) <> "" Or txtIntTerms <> vbNullString Then
        cboIntTerms = Trim(txtIntTerms)
    Else
        cboIntTerms.ListIndex = -1
    End If
iTGErrorHandler:
If err.Number = 383 Then
    MsgBox "Error in Terms. Please update Customer File and Terms of Payment Setup.", vbInformation, msgTtl
End If
End Sub

Private Sub txtInvNo_LostFocus()
    'Does Code Already Exist
    If Mode = AddNewEdit Then
        If Trim(txtInvNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, msgTtl
            If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
            txtInvNo.SetFocus
            Exit Sub
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtInvNo = Trim(txtInvNo)
            If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
                MsgBox "Sales invoice No. already exist.", vbInformation, msgTtl
                txtInvNo.SetFocus
            End If
        End If
    End If
End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgSI.Col = 3
    dtgSI.SetFocus
End Sub

Private Sub txtMSCode_Change()
    txtMSDesc = ""
    txtMSDesc = GetValueFrTable("cDescription", "CLASSIFICATION", "cClassCode = '" & Trim(txtMSCode) & "' AND cType = 'MS'")
End Sub

Private Sub txtMSCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtMSDesc) = "" And Trim(txtMSCode) <> "" Then cmdPickMS_Click
End Sub

Private Sub txtPDCode_Change()
    txtPDDesc = ""
    txtPDDesc = GetValueFrTable("cDescription", "CLASSIFICATION", "cClassCode = '" & Trim(txtPDCode) & "' AND cType = 'PD'")
End Sub

Private Sub txtPDCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtPDDesc) = "" And Trim(txtPDCode) <> "" Then cmdPickPD_Click
End Sub

Private Sub txtPaymentType_Change()
    If Trim(txtPaymentType) <> "" Or txtPaymentType <> vbNullString Then
        cboPaymentType = Trim(txtPaymentType)
    Else: cboPaymentType.ListIndex = -1
    End If
End Sub

Private Sub txtSMCode_Change()
    txtSMName = ""
    txtSMName = GetValueFrTable("cName", "SALESMAN", "cCode = '" & Trim(txtSMCode) & "'")
End Sub

Private Sub txtSMCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtSMName) = "" And Trim(txtSMCode) <> "" Then cmdPickSM_Click
End Sub

Private Sub txtTerms_Change()
On Error GoTo iTGErrorHandler
    If Trim(txtTerms) <> "" Or txtTerms <> vbNullString Then
        cboTerms = Trim(txtTerms)
    Else: cboTerms.ListIndex = -1
    End If

iTGErrorHandler:
If err.Number = 383 Then
    MsgBox "Error in Terms. Please update Customer File and Terms of Payment Setup.", vbInformation, msgTtl
    Resume Next
End If

End Sub

Private Sub txtType_Change()
Dim sCode As String
On Error Resume Next
    If Trim(txtType) <> "" Or txtType <> vbNullString Then
        cboType = Trim(txtType)
    Else: cboType.ListIndex = -1
    End If

    If Mode <> AddNewEdit Then Exit Sub
        If rsHeader!cType = "Invoice w/ DR" Then
            lSystemGeneratedSI = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = 'AUTO_NUMBER_SIDR' ")
            If lSystemGeneratedSI Then rsHeader!cInvNo = AutoNum.Generate_CtrlNo2("AUTO_NUMBER_SIDR", Format(Now, "mm/dd/yyyy"))
        ElseIf rsHeader!cType = "Billing Statement" Then
            lSystemGeneratedSI = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = 'AUTO_NUMBER_SIBILLING' ")
            If lSystemGeneratedSI Then rsHeader!cInvNo = AutoNum.Generate_CtrlNo2("AUTO_NUMBER_SIBILLING", Format(Now, "mm/dd/yyyy"))
        ElseIf rsHeader!cType = "Reimbursement" Then
            lSystemGeneratedSI = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = 'AUTO_NUMBER_REIM' ")
            If lSystemGeneratedSI Then rsHeader!cInvNo = AutoNum.Generate_CtrlNo2("AUTO_NUMBER_REIM", Format(Now, "mm/dd/yyyy"))
        End If
        
    ShowInvoiceBalance
    ComputeNet
    ComputeAmount
    ComputeGross
    ComputeTotal
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    MandatoryOK = True
    If Trim(txtInvNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Invoice Number' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtInvNo.SetFocus
        Exit Function
    End If
    
    If Trim(rsHeader!cType) <> "Consignment" Then
        ComputeAmount
        ComputeGross
    End If
    
    ComputeNet
    ComputeAmount
    ComputeGross
    ComputeTotal
    If rsHeader.Status = adRecNew Then
        If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
            MandatoryOK = False
            MsgBox "Sales invoice No. already exist.", vbInformation, msgTtl
            txtInvNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboType.SetFocus
        Exit Function
    ElseIf Trim(txtCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Customer' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtCode.SetFocus
        Exit Function
    ElseIf Trim(txtSMCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Salesman' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtSMCode.SetFocus
        Exit Function
    ElseIf Trim(txtIntTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Internal Terms' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboIntTerms.SetFocus
        Exit Function
    ElseIf Trim(txtTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Actual Terms' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboTerms.SetFocus
        Exit Function
    ElseIf Trim(txtPaymentType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Payment Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboPaymentType.SetFocus
        Exit Function
    ElseIf Trim(txtDocType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Doc Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtDocType.SetFocus
        Exit Function
    End If
    
    GetChild
    
    'Transaction without details
    If rsDetail.RecordCount < 1 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, msgTtl
        dtgSI.SetFocus
        Exit Function
    End If
    
    GetChild
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else: rsDetail.MoveNext
            End If
        Else: rsDetail.MoveNext
        End If
    Loop
    
'    GetChild
'
'    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
'    Do Until rsDetail.EOF
'        If rsDetail!cWH = "" Then
'            MandatoryOK = False
'            MsgBox "Warehouse is required.", vbInformation, msgTtl
'            Exit Function
'        End If
'        rsDetail.MoveNext
'    Loop
    
    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, msgTtl
        MandatoryOK = False
        Exit Function
    End If
    
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.EOF
            rsDetail!nIdentity = rsDetail.AbsolutePosition
            rsDetail.MoveNext
        Loop
    End If
End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgSI.DataSource = Nothing
    dtgSI.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtInvNo.Locked = False
    txtInvNo.SetFocus
    
    Mode = Find
    lblVat.Visible = False
    
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cboType.Enabled = lEnable
    cboDocType.Enabled = lEnable
    cmdPickCode.Enabled = lEnable
    cmdPickMS.Enabled = lEnable
    cmdPickPD.Enabled = lEnable
    cmdPickSM.Enabled = lEnable
    cmdPickProject.Enabled = lEnable
    cboIntTerms.Enabled = lEnable
    cboTerms.Enabled = lEnable
    cboPaymentType.Enabled = lEnable
    cboTaxType.Enabled = lEnable
    cmdPickWork.Enabled = lEnable
End Sub

'Add DR Detals from picklist to details recordset
Public Sub AddDetailsFromList()
    GetChild
    With frmRefList.lvwList
        For i = 1 To .ListItems.Count
            If .ListItems(i).Checked = True Then
                ListToGrid i
            End If
        Next i
                        
        sSQL = "Select lVatInclusive, nVATRate, cTaxType from DR where cDRNo = '" & Trim(rsDetail!cRefNo) & "'"
        Set rs = New Recordset
        rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        cn.CommandTimeout = 120
        
        If rs.RecordCount <> 0 Then
            rsHeader!lVatinclusive = rs!lVatinclusive
            rsHeader!nVatRate = rs!nVatRate
            rsHeader!cTaxType = rs!cTaxType
            lblVat.Visible = False
            lblVat.Caption = IIf(rsHeader!lVatinclusive, "Inclusive", "Exclusive")
            If rsHeader!cTaxType = "VAT" Then lblVat.Visible = True
        End If
        
    End With

    GetChild
    
    ComputeTotal
    EditDetail True
End Sub

'Private Sub RemoveSameItem()
'    Dim i As Integer
'    If rsDetail.RecordCount <> 0 Then
'        vBM = rsDetail.Bookmark
'        rsDetail.MoveFirst
'        While Not rsDetail.EOF
'            If rs.State = adStateOpen Then rs.Close
'            rs.Open rsDetail.Source, cn, adOpenStatic, adLockReadOnly
'            rs.Filter = ""
'            While Not rs.EOF
'                rs
'                rs.MoveNext
'            Loop
'            rs.Close
'            rsDetail.MoveNext
'        Loop
'    End If
'End Sub

'From pick list to datagrid
Sub ListToGrid(i As Integer)
Dim cSO, cSONO As String
Dim nSO_I As Long
Dim nDisc As Double
    
    cSONO = ""
        
    With frmRefList.lvwList
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cInvNo = Trim(rsHeader!cInvNo)
        rsDetail!cRefNo = Trim(frmRefList.mRefPK)
        rsDetail!cItemNo = Trim(.ListItems(i).Text)
        rsDetail!cDesc = Trim(.ListItems(i).SubItems(1))
        rsDetail!cWH = Trim(.ListItems(i).SubItems(2))
        rsDetail!cUnit = Trim(.ListItems(i).SubItems(3))
        rsDetail!nQty = CDbl(.ListItems(i).SubItems(4))
        rsDetail!nPrice = CDbl(.ListItems(i).SubItems(5))
        rsDetail!nNetPrice = CDbl(.ListItems(i).SubItems(5))
        rsDetail!nAmount = CDbl(.ListItems(i).SubItems(6))
        rsDetail!nRefIdentity = CDbl(.ListItems(i).SubItems(7))
        rsDetail!nFactor = CDbl(.ListItems(i).SubItems(8))
        rsDetail!nCost = CDbl(.ListItems(i).SubItems(9))
        If (UCase(Trim(cboType)) = "INVOICE") Then
            cSO = Trim(frmRefList.mRefPK)
            nSO_I = CDbl(.ListItems(i).SubItems(7))
        Else
            cSO = GetValueFrTable("cRefNo", "DR_T", "cDRNo = '" & Trim(frmRefList.mRefPK) & "' AND nIdentity = '" & CDbl(.ListItems(i).SubItems(7)) & "'")
            nSO_I = GetValueFrTable("nRefIdentity", "DR_T", "cDRNo = '" & Trim(frmRefList.mRefPK) & "' AND nIdentity = '" & CDbl(.ListItems(i).SubItems(7)) & "'")
        End If
        
        rsDetail!cPricing = GetValueFrTable("cPricing", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nUDPrice = GetValueFrTable("nPrice", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!cDiscount = GetValueFrTable("cDiscount", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nTPC = GetValueFrTable("nTPC", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!nSMCom = GetValueFrTable("nSMCom", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        rsDetail!cCosting = GetValueFrTable("cCosting", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")

    End With
End Sub

'Datagrid state when adding/editing transactions
Sub EditDetail(bval As Boolean)
    If (UCase(Trim(cboType)) = "INVOICE") Then
        dtgSI.Columns(1).Button = bval
        dtgSI.Columns(5).Locked = Not bval
        dtgSI.Columns(6).Locked = Not bval
    ElseIf UCase$(Trim$(cboType)) = "INVOICE W/ DR" Then
        dtgSI.Columns(6).Locked = Not bval
    ElseIf UCase$(Trim$(cboType)) = "BILLING STATEMENT" Then
        dtgSI.Columns(6).Locked = Not bval
    End If
End Sub

'Computes total amount per detail line
Private Sub ComputeAmount()
Dim nAmount As Double
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
'    With dtgSI
'        If Trim(rsHeader!cType) <> "Consignment" Then
'        nAmount = IIf(IsNull(.Columns(6).Value), 0, .Columns(6).Value) * _
'                    IIf(IsNull(.Columns(5).Value), 0, .Columns(5).Value)
'        .Columns(7).Text = Format(nAmount, "###,##0.#0")
'        Else
'            nAmount = IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value)
'            .Columns(7).Text = Format(nAmount, "###,##0.#0")
'        End If
'    End With
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do While Not rsDetail.EOF
            nAmount = IIf(IsNull(rsDetail!nPrice), 0, rsDetail!nPrice) * IIf(IsNull(rsDetail!nQty), 0, rsDetail!nQty)
            rsDetail!nAmount = Round(rsDetail!nPrice, 4) * CDec(IIf(IsNull(rsDetail!nQty), 0, rsDetail!nQty))
            rsDetail.MoveNext
        Loop
    End If
    
End Sub

'Computes gross per detail line
Private Sub ComputeGross()
Dim nGross As Double
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do While Not rsDetail.EOF
            rsDetail.MoveNext
            nGross = rsDetail!nPrice * rsDetail!nQty
            rsDetail!nAmount = Format(nGross, "###,##0.#0")
        Loop
    End If
    With dtgSI
    End With
End Sub

'Gross amount
Public Sub ComputeTotal()
Dim n, nTPC, m, d, nTaxRate As Double
On Error Resume Next
          If Mode <> AddNewEdit Then Exit Sub
          n = 0
          m = 0
          nTPC = 0
          Set rs = New Recordset
          Set rs = rsDetail.Clone
          rs.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"
          rs.MoveFirst
          If rsHeader!cType = "Invoice w/ DR" Then
                    Do Until rs.EOF
                              nTPC = nTPC + IIf(IsNull(rs!nTPC), 0, rs!nTPC)
                              n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
'                              If IsNull(rs!cDiscount) Or rs!cDiscount = "" Then
'                                        d = 0
'                              Else: d = d + ((IIf(IsNull(rs!nPrice), 0, rs!nPrice) - IIf(IsNull(rs!nNetPrice), 0, rs!nNetPrice)) * IIf(IsNull(rs!nQty), 0, rs!nQty))
'                              End If
                              rs.MoveNext
                    Loop
                    
                    Set rs = Nothing
                    If rsHeader!lVatinclusive Then
                              'm = (n - rsHeader!nDiscount) * (1 - (1 / (1 + rsHeader!nVatRate / 100)))
                              m = n * (1 - (1 / (1 + rsHeader!nVatRate / 100)))
                    Else: m = n * (rsHeader!nVatRate / 100)
                    End If
          Else
                    rsHeader!lVatinclusive = 1
                    If rsHeader!cTaxType = "VAT" Then
                              rsHeader!nVatRate = GetValueFrTable("cValue", "System_Option", "cCode = 'DEF_VAT_RATE'")
                    Else: rsHeader!nVatRate = 0
                    End If
                    
                    Do Until rs.EOF
                              nTPC = nTPC + IIf(IsNull(rs!nTPC), 0, rs!nTPC)
                              n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
'                              If IsNull(rs!cDiscount) Or rs!cDiscount = "" Then
'                                        d = 0
'                              Else: d = d + ((IIf(IsNull(rs!nPrice), 0, rs!nPrice) - IIf(IsNull(rs!nNetPrice), 0, rs!nNetPrice)) * IIf(IsNull(rs!nQty), 0, rs!nQty))
'                              End If
                              rs.MoveNext
                    Loop
                    
                    Set rs = Nothing
                    If rsHeader!lVatinclusive Then
                              m = n * (1 - (1 / (1 + rsHeader!nVatRate / 100)))
                    Else: m = n * (rsHeader!nVatRate / 100)
                    End If
          End If
                
          m = Round(m, 2)
          d = rsDetail!nDiscount
          rsHeader!nSubTotal = IIf(rsHeader!lVatinclusive, n - m, n)
          d = rsHeader!nDiscount
          rsHeader!nVAT = Round(m, 2)
          rsHeader!nGross = IIf(rsHeader!lVatinclusive, n, n + m) - CDbl(txtFreightAllow) + CDbl(txtFreightCharges)
          rsHeader!nDiscount = d
          rsHeader!nBalance = IIf(rsHeader!lVatinclusive, n, n + m) - d
          rsHeader!nTPCGross = nTPC
         
          With rsHeader
                    !nSubTotal = IIf(rsHeader!lVatinclusive, Round(n, 2) - Round(m, 2), Round(n, 2))
                    !nVatAmount = Round(m, 2)
                    !nGross = IIf(rsHeader!lVatinclusive, Round(n, 2), Round(n, 2) + Round(m, 2))
          End With
End Sub

'Inserts into DR & DR_T tables

'Update cInvNo field on DR table
Private Function UpdateDRSI() As Boolean
On Error GoTo FunctionExit
    
    UpdateDRSI = False
    
    rsDetail.MoveFirst
    
    Do While Not rsDetail.EOF
        cn.Execute ("UPDATE DR SET cInvNo = '" & Trim(rsHeader!cInvNo) & "' WHERE cDRNo = '" & Trim(rsDetail!cRefNo) & "' AND cCompanyID = '" & COID & "'")
        rsDetail.MoveNext
    Loop
    
    UpdateDRSI = True

FunctionExit:
    Exit Function

End Function

'Show the balances of each sales invoice
'Binding of the textboxex was disabled
Private Sub ShowInvoiceBalance()
Dim rsBalance As New Recordset

    If Mode = AddNewEdit Then Exit Sub
    
    sSQL = "SELECT *, ISNULL((nSales - nPaid - nReturns - nCredit + nDebit), 0) AS nBalance " & _
            "FROM V_SalesBalanceInquiry WHERE cInvNo = '" & rsHeader!cInvNo & "' AND cCompanyID = '" & COID & "'"
    rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    txtDebit = 0
    txtCredit = 0
    txtReturns = 0
    txtPayment = 0
    txtBalance = 0
    
    If rsBalance.RecordCount <> 0 Then
        txtDebit = rsBalance!nDebit
        txtCredit = rsBalance!nCredit
        txtReturns = rsBalance!nReturns
        txtPayment = rsBalance!nPaid
        txtBalance = rsBalance!nBalance
    End If

'    Set rsBalance = Nothing
    
End Sub

Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    'Cannot edit if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot edit Invoice with collection.", vbCritical + vbExclamation, msgTtl
        AllowEdit = False
        Exit Function
    ElseIf UCase(Trim(rsHeader!cType)) = "AUTO-INVOICE" Then
        MsgBox "Cannot EDIT Auto-generated Invoice.", vbInformation, msgTtl
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    'Cannot delete if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot " & sAction & " transaction with collection.", vbCritical + vbExclamation, msgTtl
        AllowDelete = False
        Exit Function
    ElseIf UCase(Trim(rsHeader!cType)) = "AUTO-INVOICE" Then
        MsgBox "Cannot DELETE Auto-generated Invoice. " & vbCr & _
        "Please DELETE Source Delivery Reciept.", vbInformation, msgTtl
        AllowDelete = False
        Exit Function
    ElseIf GetValueFrTable("cInvNo", "AR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot DELETE Invoice with CM/DM Adjustments.", vbInformation, msgTtl
        AllowDelete = False
        Exit Function
    ElseIf GetValueFrTable("cRefNo", "WRR_T", "cRefNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot DELETE Invoice with Receiving Report.", vbInformation, msgTtl
        AllowDelete = False
        Exit Function

    End If
    
    'Delete existing reference delivery receipt for this transaction
    If (UCase(Trim(cboType)) = "INVOICE") Then
        If MsgBox("Transaction type is 'Sales without DR'. Reference delivery receipt for this transaction will also be deleted. Proceed anyway?", vbCritical + vbOKCancel, msgTtl) = vbCancel Then
            AllowDelete = False
            Exit Function
        End If
        cn.Execute ("DELETE DR_T WHERE cDRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
        cn.Execute ("DELETE DR WHERE cDRNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    Else: cn.Execute ("UPDATE DR SET cInvNo = NULL WHERE cInvNo = '" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    End If
    
    cn.Execute ("DELETE AR_T WHERE cTranNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")
    cn.Execute ("DELETE AR WHERE cTranNo = 'SI-" & Trim$(rsHeader!cInvNo) & "' AND cCompanyID = '" & COID & "'")

End Function

'Checks the credit status of the client
Function SICreditLimitOK() As Boolean
Dim sCode, sPCCode As String
Dim lCHold As Boolean
    
    If Not GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_SI'") Then
        SICreditLimitOK = True
        Exit Function
    End If
    
    MousePointer = vbHourglass
    FormWaitShow App.Path & "\Transmit.avi", "Checking Credit Limit Balance . . ."

    sCode = Trim(txtCode)
    
    cn.CommandTimeout = 600
    If Not GetValueFrTable("lGroupLimit", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'") Then
        'Query for independent client
        sSQL = "SELECT cCompanyID, cCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, SUM(CAST(lHold AS INT)) AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimitBalance) AS nLimitBalance " & _
                "From V_CG " & _
                "WHERE cCode = '" & sCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cCode"
    Else
        sPCCode = GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        lCHold = GetValueFrTable("lHold", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        'Query for customer affecting parent company
        sSQL = "SELECT cCompanyID, cGroupCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, " & IIf(lCHold, "1", "0") & " AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimit - nAR - nPDC - nSOAmtLeft) AS nLimitBalance " & _
                "From V_CG_PC " & _
                "WHERE cGroupCode = '" & sPCCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cGroupCode"
    End If
    
    Set rs = New Recordset
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    cn.CommandTimeout = 120
    
    If rs.RecordCount > 0 Then
        nLimit = rs!nLimit
        nAR = rs!nAR
        nARPastDue = rs!nARPastDue
        nPDC = rs!nPDC
        nHold = rs!nHold
        nBounced = rs!nBounced
        nSOAmtLeft = rs!nSOAmtLeft
        nLimitBalance = rs!nLimitBalance
    Else
        nLimit = 0
        nAR = 0
        nARPastDue = 0
        nPDC = 0
        nHold = 0
        nBounced = 0
        nSOAmtLeft = 0
        nLimitBalance = 0
    End If
    
    'Is Credit OK?
    Dim cHold, cOCL, cPDAR, cRTC As String
    
    SICreditLimitOK = True
    If nHold > 0 Then
        cHold = "Customer on Hold"
        SICreditLimitOK = False
    End If
    If nLimitBalance < 0 Then
        cOCL = "Over Credit Limit [Php " & Format((-1 * nLimitBalance), "#,##0.#0") & "]"
        SICreditLimitOK = False
    End If
    If nARPastDue > 0 Then
        cPDAR = "With Past Due A/R [Php " & Format(nARPastDue, "#,##0.#0") & "]"
        SICreditLimitOK = False
    End If
    If nBounced > 0 Then
        cRTC = "With Bounced Check"
        SICreditLimitOK = False
    End If

    FormWaitHide
    MousePointer = vbDefault
    
    lOverride = False
    
    If Not SICreditLimitOK Then
        MsgBox "Cannot proceed transaction with customer " & sCode & " due to following reason/s:" & vbCr & _
               cHold & IIf((cOCL <> ""), " | " & cOCL, "") & _
               IIf((cPDAR <> ""), " | " & cPDAR, "") & _
               IIf((cRTC <> ""), " | " & cRTC, ""), vbCritical, Me.Caption
        If nBounced = 0 Then
            RepName = Trim(txtInvNo)
            frmOverride.mOverridingType = O_SI
            frmOverride.Show vbModal
            If gAction = G_OK Then
                lOverride = True
                SICreditLimitOK = True
                cmdPickSM.SetFocus
                Exit Function
            Else
                txtCode = ""
                txtCode.SetFocus
            End If
        Else
            txtCode = ""
            txtCode.SetFocus
        End If
    End If
    
End Function

Private Sub GetCtrlNo(sCode As String)
Dim lCtrlNoOk As Boolean
    strNo = rsAuto!cValue
    Do Until lCtrlNoOk
        If IDExisting(rsHeader, "cInVNo", "Sales", Left(strNo, 5) + Format(CStr((CInt(Right(strNo, 5)) + 1)), "00000")) Then
            strNo = Left(strNo, 5) + Format(CStr((CInt(Right(strNo, 5)) + 1)), "00000")
        Else: lCtrlNoOk = True
        End If
    Loop
    
    If Mid(strNo, 4, 2) <> Format(Date, "yy") Then
        txtInvNo = Format(1, "00000")
        strNo = Left(strNo, 3) + Format(Date, "yy") + "00000"
    Else: txtInvNo = Left(strNo, 3) + Format(Date, "yy") + Format(Right(strNo, 5) + 1, "00000")
    End If
End Sub



Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtInvNo.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cInvNo LIKE '" & Trim$(txtInvNo.Text) & "%'"
    If Trim$(dtbDate.Text) <> "__/__/____" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    If Trim$(txtType.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cType LIKE '" & Trim$(txtType.Text) & "%'"
    If Trim$(txtDocType.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDocType LIKE '" & Trim$(txtDocType.Text) & "%'"
    If Trim$(txtCode.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cCode LIKE '" & Trim$(txtCode.Text) & "%'"
    If Trim$(txtMSCode.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cMSCode LIKE '" & Trim$(txtMSCode.Text) & "%'"
    If Trim$(txtPDCode.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPDCode LIKE '" & Trim$(txtPDCode.Text) & "%'"
    If Trim(txtSMCode.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cSMan LIKE '" & Trim$(txtSMCode.Text) & "%'"
    If Trim(txtIntTerms.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cIntTerm LIKE '" & Trim$(txtIntTerms.Text) & "%'"
    If Trim(txtTerms.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTerm LIKE '" & Trim$(txtTerms.Text) & "%'"
    If Trim(txtPaymentType.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPayType LIKE '" & Trim$(txtPaymentType.Text) & "%'"
    If Trim$(txtTaxType.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTaxType LIKE '" & Trim$(txtTaxType.Text) & "%'"
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function


'Update system generated number
'Change Transaction Number
Sub ChangeTranNo(strTranNo As String)
    GetChild
    
    rsHeader!cInvNo = strTranNo
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        rsDetail!cInvNo = strTranNo
        rsDetail.MoveNext
    Loop
    
    GetChild
End Sub

Public Sub ComputeTotalDisc()
Dim n As Double
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    n = 0
    Set rs = New Recordset
    Set rs = rsDetail.Clone
    rs.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"

    rs.MoveFirst
    Do Until rs.EOF
        If IsNull(rs!cDiscount) Or rs!cDiscount = "" Then
        n = 0
        Else
        n = n + ((IIf(IsNull(rs!nPrice), 0, rs!nPrice) - IIf(IsNull(rs!nNetPrice), 0, rs!nNetPrice)) * IIf(IsNull(rs!nQty), 0, rs!nQty))
        End If
        rs.MoveNext
    Loop
    Set rs = Nothing
    
    rsHeader!nDiscount = n
    
End Sub

Private Sub ComputeNet()
Dim si, l As Integer
Dim s(0 To 15), ns, disc As String
Dim lStop As Boolean
On Error GoTo ErrHandler
    
    lNetOK = True
    
    If rsDetail.RecordCount = 0 Then Exit Sub
    If IsNull(rsDetail!cItemNo) Then Exit Sub
    If Trim(rsDetail!cItemNo) = "" Then Exit Sub
    
    lNetOK = False
    
    disc = rsDetail!cDiscount
    net = rsDetail!nPrice  'dtgSO.Columns(6).Value
        
    If disc <> "" Then
        l = Len(disc)
        i = 1
        si = 0
        Do While Not i = l + 1
            cString = Mid(disc, i, 1)
            If cString <> "/" Then
                ns = ns + cString
                s(si) = ns
            Else: si = si + 1
                ns = ""
            End If
            i = i + 1
        Loop
                
        si = 0
        lStop = False
        
        Do While Not lStop
            If s(si) <> "" Then
                If Not IsNumeric(s(si)) Then GoTo ErrHandler
                si = si + 1
            Else: lStop = True
            End If
        Loop
        
        si = 0
        lStop = False
        
        Do While Not lStop
            If s(si) <> "" Then
                If Right(s(si), 1) = "-" Then GoTo ErrHandler
                If (Mid(s(si), 1, 1) = "-") Then
                    net = net + CDbl(s(si))
                Else: net = net - (net * (CDbl(s(si)) * 0.01))
                End If
                si = si + 1
            Else: lStop = True
            End If
        Loop
    
    End If
    
    If s(0) = "" Then rsDetail!cDiscount = ""
    
    rsDetail!nNetPrice = net 'Round(net, 4)
    lNetOK = True
    
ErrHandler:
    If Not lNetOK Then
        MsgBox "Invalid discount format! (ex: '10/5/-100', '-100/10/5', '10/-100/5')", vbCritical, msgTtl
        lLessAmount = False
        lLessPercent = False
    End If

End Sub


Public Sub ShowForm(sTranNo As String)
    If Mode = Find Then

        OpenNewConnection connHeader
        OpenNewConnection connDetail

        Set rsHeader = Nothing
        Set rsDetail = Nothing
        Set rsHeader = New ADODB.Recordset
        Set rsDetail = New ADODB.Recordset

        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE cInvNo = '" & Trim(sTranNo) & "'"
        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE cInvNo = '" & Trim(sTranNo) & "' AND cType <> 'Van Selling'"

        Set FrmName = Me
        FormLocking True

        If rsHeader.RecordCount = 0 Then
            FormWaitHide
            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
            RSZero
            FormSearch True
            SearchObj True
            Mode = Find
            Exit Sub
        End If
            SetDataSource
            SetDataField
            txtInvNo.BackColor = &HE0FFFF
            Mode = Normal
            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True

            'BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True, True

    End If
End Sub

Private Sub txtWork_Change()
    txtWorkDesc = ""
    If txtProject.Text = "" Then: txtProject.SetFocus: Exit Sub
    txtWorkDesc = GetValueFrTable("Description", "Work_Maintenance_File", "WOrkNo = '" & Trim(txtWork) & "' ") 'and cProjectNo =  '" & Trim(txtProject) & "'")
End Sub

Private Sub txtWork_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtWork) = "" And Trim(txtWork) <> "" Then cmdPickWork_Click
End Sub
